package com.yxhl.zoume.core.user.ui.fragment.identification;


import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.yxhl.zoume.IDentificationErroeDataBinding;
import com.yxhl.zoume.R;
import com.yxhl.zoume.UIConstants;
import com.yxhl.zoume.common.ui.fragment.BaseDataBindingFragment;
import com.yxhl.zoume.core.user.ui.activity.NameIdentificationActivity;
import com.yxhl.zoume.data.http.rest.response.identification.IdentificationResponse;

import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 项目名称：Ferrari
 * Created by menggod on 16/9/20 .
 * 失败
 */
public class IdentificationErrorFragment extends BaseDataBindingFragment {

    IdentificationResponse mIdentificationResponse;
    private IDentificationErroeDataBinding mDataBinding;

    public IdentificationErrorFragment() {
        // Required empty public constructor
    }

    public static IdentificationErrorFragment newInstance(IdentificationResponse identificationResponse) {

        Bundle bundle = new Bundle();
        bundle.putSerializable(UIConstants.IDCertify.ARGUMENT_KEY_ID_CERTIFY, identificationResponse);

        IdentificationErrorFragment fragment = new IdentificationErrorFragment();
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = super.onCreateView(inflater, container, savedInstanceState);


        ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        parseArguments();
    }


    private void parseArguments() {
        Bundle bundle = getArguments();
        if (bundle != null) {
            mIdentificationResponse = (IdentificationResponse)
                    bundle.getSerializable(UIConstants.IDCertify.ARGUMENT_KEY_ID_CERTIFY);
            mDataBinding.setResponse(mIdentificationResponse);
        }
    }

    @Override
    protected void initializeInjector() {

    }

    @Override
    protected View getContentLayout(LayoutInflater inflater, ViewGroup container) {
        mDataBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_identification_error, container, false);
        return mDataBinding.getRoot();
    }


    @Override
    protected void setupToolBar() {
        ((NameIdentificationActivity) mActivity).setToolbarTitle(R.string.identification_header_title);
    }

    @OnClick(R.id.btn_re_auth)
    public void onClick() {
        NameIdentificationActivity activity = (NameIdentificationActivity) getActivity();
        activity.replaceFragment(R.id.frame_activity_name_identification_content, IdentificationPrepareFragment.newInstance(null), false);
    }
}
